package book

import (
	"NovelBook/dao"
	"NovelBook/models/db_models"
	"NovelBook/models/res"
	"strings"
)

func SearchIntersection(query res.Query) ([]db_models.Books, error) {
	var books []db_models.Books
	query.Name = strings.Replace(query.Name, "%", "\\%", -1)
	query.Publisher = strings.Replace(query.Publisher, "%", "\\%", -1)
	err := dao.GetDb().Where("name LIKE ? AND author LIKE ? AND publisher LIKE ?", "%"+query.Name+"%", "%"+query.Author+"%", "%"+query.Publisher+"%").Find(&books).Error
	if err != nil {
		return nil, err
	}
	return books, nil
}
